package com.istock.sampleservice.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.istock.base.common.api.model.PageInfo;
import com.istock.sampleService.model.SenvonInfoVO;
import com.istock.servicesample.dao.SenvonInfoMapper;
import com.istock.servicesample.model.SenvonInfo;
import com.istock.servicesample.model.SenvonInfoExample;

@Repository
public class SenvonInfoService {

	@Autowired
	private SenvonInfoMapper mapper;
	
	@Transactional
	public SenvonInfo createRecord(String name) {
		SenvonInfo record = new SenvonInfo();
		record.setTestName(name);
		record.setUpdateTime(new Date());
		mapper.insertSelective(record);
		
		return record;
	}
	
	public List<SenvonInfoVO> findByName(String name , PageInfo<SenvonInfoVO> page){
		SenvonInfoExample example = new SenvonInfoExample();
		SenvonInfoExample.Criteria criteria = example.createCriteria();
		criteria.andTestNameLike("%"+name+"%");
		
		List<SenvonInfo> list = mapper.selectByExample(example, page);
		
		List<SenvonInfoVO> result = new ArrayList<SenvonInfoVO>();
		if(list != null && list.size()>0) {
			for(SenvonInfo info : list) {
				SenvonInfoVO vo = new SenvonInfoVO();
				BeanUtils.copyProperties(info, vo);
				result.add(vo);
			}
		}
		
		return result;
	}
}
